public class O42 {
    public static void main(String[] args) {
        O42 o = new O42();
        System.out.println(o.maxSubArray(new int[]{-2,1,-3,4,-1,2,1,-5,4}));
    }
    public int maxSubArray(int[] nums) {
        int re = nums[0];
        int[] dp = new int[nums.length];
        dp[0] = nums[0];
        for (int i = 1; i < nums.length; i++) {
            dp[i] = Math.max(nums[i],dp[i-1]+nums[i]);
            re = Math.max(re,dp[i]);
        }
        return re;
    }
}
